<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="${comment}" prop="orderNumber">
        <el-input
          v-model="queryParams.orderNumber"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="passengerInfoId">
        <el-input
          v-model="queryParams.passengerInfoId"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="passengerPhone">
        <el-input
          v-model="queryParams.passengerPhone"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="driverPhone">
        <el-input
          v-model="queryParams.driverPhone"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="carId">
        <el-input
          v-model="queryParams.carId"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="plateNumber">
        <el-input
          v-model="queryParams.plateNumber"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="startLongitude">
        <el-input
          v-model="queryParams.startLongitude"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="startLatitude">
        <el-input
          v-model="queryParams.startLatitude"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="startAddress">
        <el-input
          v-model="queryParams.startAddress"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="endAddress">
        <el-input
          v-model="queryParams.endAddress"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="startTime">
        <el-date-picker clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="orderStartTime">
        <el-date-picker clearable
          v-model="queryParams.orderStartTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="endLongitude">
        <el-input
          v-model="queryParams.endLongitude"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="endLatitude">
        <el-input
          v-model="queryParams.endLatitude"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="driverGrabTime">
        <el-date-picker clearable
          v-model="queryParams.driverGrabTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="receivePassengerTime">
        <el-date-picker clearable
          v-model="queryParams.receivePassengerTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="passengerGetoffTime">
        <el-date-picker clearable
          v-model="queryParams.passengerGetoffTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="passengerGetoffLongitude">
        <el-input
          v-model="queryParams.passengerGetoffLongitude"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="passengerGetoffLatitude">
        <el-input
          v-model="queryParams.passengerGetoffLatitude"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="isEvaluate">
        <el-input
          v-model="queryParams.isEvaluate"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="isPaid">
        <el-input
          v-model="queryParams.isPaid"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="isCancel">
        <el-input
          v-model="queryParams.isCancel"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="isAdjust">
        <el-input
          v-model="queryParams.isAdjust"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="isDissent">
        <el-input
          v-model="queryParams.isDissent"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="timeInCar">
        <el-date-picker clearable
          v-model="queryParams.timeInCar"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择${comment}">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="${comment}" prop="orderMoney">
        <el-input
          v-model="queryParams.orderMoney"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="tombstone">
        <el-input
          v-model="queryParams.tombstone"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="deleteOrNo">
        <el-input
          v-model="queryParams.deleteOrNo"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="cityCode">
        <el-input
          v-model="queryParams.cityCode"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['bill:bill:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['bill:bill:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['bill:bill:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['bill:bill:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="billList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="${comment}" align="center" prop="orderNumber" />
      <el-table-column label="${comment}" align="center" prop="passengerInfoId" />
      <el-table-column label="${comment}" align="center" prop="passengerPhone" />
      <el-table-column label="${comment}" align="center" prop="driverStatus" />
      <el-table-column label="${comment}" align="center" prop="driverPhone" />
      <el-table-column label="${comment}" align="center" prop="carId" />
      <el-table-column label="${comment}" align="center" prop="plateNumber" />
      <el-table-column label="${comment}" align="center" prop="startLongitude" />
      <el-table-column label="${comment}" align="center" prop="startLatitude" />
      <el-table-column label="${comment}" align="center" prop="startAddress" />
      <el-table-column label="${comment}" align="center" prop="endAddress" />
      <el-table-column label="${comment}" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="orderStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.orderStartTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="endLongitude" />
      <el-table-column label="${comment}" align="center" prop="endLatitude" />
      <el-table-column label="${comment}" align="center" prop="driverGrabTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.driverGrabTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="receivePassengerTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.receivePassengerTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="passengerGetoffTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.passengerGetoffTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="passengerGetoffLongitude" />
      <el-table-column label="${comment}" align="center" prop="passengerGetoffLatitude" />
      <el-table-column label="${comment}" align="center" prop="serviceType" />
      <el-table-column label="${comment}" align="center" prop="status" />
      <el-table-column label="${comment}" align="center" prop="isEvaluate" />
      <el-table-column label="${comment}" align="center" prop="payType" />
      <el-table-column label="${comment}" align="center" prop="isPaid" />
      <el-table-column label="${comment}" align="center" prop="isCancel" />
      <el-table-column label="${comment}" align="center" prop="isAdjust" />
      <el-table-column label="${comment}" align="center" prop="isDissent" />
      <el-table-column label="${comment}" align="center" prop="timeInCar" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.timeInCar, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="${comment}" align="center" prop="orderMoney" />
      <el-table-column label="${comment}" align="center" prop="tombstone" />
      <el-table-column label="${comment}" align="center" prop="deleteOrNo" />
      <el-table-column label="${comment}" align="center" prop="cityCode" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['bill:bill:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['bill:bill:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改账单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="${comment}" prop="orderNumber">
          <el-input v-model="form.orderNumber" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="passengerInfoId">
          <el-input v-model="form.passengerInfoId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="passengerPhone">
          <el-input v-model="form.passengerPhone" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="driverPhone">
          <el-input v-model="form.driverPhone" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="carId">
          <el-input v-model="form.carId" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="plateNumber">
          <el-input v-model="form.plateNumber" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="startLongitude">
          <el-input v-model="form.startLongitude" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="startLatitude">
          <el-input v-model="form.startLatitude" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="startAddress">
          <el-input v-model="form.startAddress" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="endAddress">
          <el-input v-model="form.endAddress" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="startTime">
          <el-date-picker clearable
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="orderStartTime">
          <el-date-picker clearable
            v-model="form.orderStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="endLongitude">
          <el-input v-model="form.endLongitude" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="endLatitude">
          <el-input v-model="form.endLatitude" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="driverGrabTime">
          <el-date-picker clearable
            v-model="form.driverGrabTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="receivePassengerTime">
          <el-date-picker clearable
            v-model="form.receivePassengerTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="passengerGetoffTime">
          <el-date-picker clearable
            v-model="form.passengerGetoffTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="passengerGetoffLongitude">
          <el-input v-model="form.passengerGetoffLongitude" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="passengerGetoffLatitude">
          <el-input v-model="form.passengerGetoffLatitude" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="isEvaluate">
          <el-input v-model="form.isEvaluate" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="isPaid">
          <el-input v-model="form.isPaid" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="isCancel">
          <el-input v-model="form.isCancel" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="isAdjust">
          <el-input v-model="form.isAdjust" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="isDissent">
          <el-input v-model="form.isDissent" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="timeInCar">
          <el-date-picker clearable
            v-model="form.timeInCar"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择${comment}">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="${comment}" prop="orderMoney">
          <el-input v-model="form.orderMoney" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="tombstone">
          <el-input v-model="form.tombstone" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="deleteOrNo">
          <el-input v-model="form.deleteOrNo" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="cityCode">
          <el-input v-model="form.cityCode" placeholder="请输入${comment}" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listBill, getBill, delBill, addBill, updateBill } from "@/api/bill/bill";

export default {
  name: "Bill",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 账单表格数据
      billList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNumber: null,
        passengerInfoId: null,
        passengerPhone: null,
        driverStatus: null,
        driverPhone: null,
        carId: null,
        plateNumber: null,
        startLongitude: null,
        startLatitude: null,
        startAddress: null,
        endAddress: null,
        startTime: null,
        orderStartTime: null,
        endLongitude: null,
        endLatitude: null,
        driverGrabTime: null,
        receivePassengerTime: null,
        passengerGetoffTime: null,
        passengerGetoffLongitude: null,
        passengerGetoffLatitude: null,
        serviceType: null,
        status: null,
        isEvaluate: null,
        payType: null,
        isPaid: null,
        isCancel: null,
        isAdjust: null,
        isDissent: null,
        timeInCar: null,
        orderMoney: null,
        tombstone: null,
        deleteOrNo: null,
        cityCode: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        orderNumber: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询账单列表 */
    getList() {
      this.loading = true;
      listBill(this.queryParams).then(response => {
        this.billList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orderNumber: null,
        passengerInfoId: null,
        passengerPhone: null,
        driverId: null,
        driverStatus: null,
        driverPhone: null,
        carId: null,
        plateNumber: null,
        startLongitude: null,
        startLatitude: null,
        startAddress: null,
        endAddress: null,
        startTime: null,
        orderStartTime: null,
        endLongitude: null,
        endLatitude: null,
        driverGrabTime: null,
        receivePassengerTime: null,
        passengerGetoffTime: null,
        passengerGetoffLongitude: null,
        passengerGetoffLatitude: null,
        serviceType: null,
        status: null,
        isEvaluate: null,
        payType: null,
        isPaid: null,
        isCancel: null,
        isAdjust: null,
        isDissent: null,
        createTime: null,
        updateTime: null,
        timeInCar: null,
        orderMoney: null,
        tombstone: null,
        deleteOrNo: null,
        cityCode: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orderNumber)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加账单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderNumber = row.orderNumber || this.ids
      getBill(orderNumber).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改账单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.orderNumber != null) {
            updateBill(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBill(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderNumbers = row.orderNumber || this.ids;
      this.$modal.confirm('是否确认删除账单编号为"' + orderNumbers + '"的数据项？').then(function() {
        return delBill(orderNumbers);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bill/bill/export', {
        ...this.queryParams
      }, `bill_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
